// esModule工具
function esModule(value) {
  return value && value.__esModule ? value : {
    default: value
  }
}
// 转换为数组工具
function turnToArr(value) {
  if (Array.isArray(value)) {
    for (var num = 0, arr = Array(value.length); num < value.length; num++) arr[num] = value[num];
    return arr
  }
  return Array.from(value)
}
// symbol工具
var symbol = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (value) {
    return typeof value
  } : function (value) {
    return value && "function" == typeof Symbol && value.constructor === Symbol && value !== Symbol.prototype ? "symbol" : typeof value
  },

  requireCate = esModule(require("../../json/cate.js")),
  configGetApp = (esModule(require("../../etc/config")), getApp()),
  requireAuth = require("../../utils/auth.js"),
  requireUtil = require("../../utils/util.js"),
  WxNotificationCenter = require("../../utils/WxNotificationCenter.js");
Date.parse(new Date);
import http from '../util/request.js';
Page({
  data: {
    showModalStatus: !1,
    msgStatus: !1,
    sexDataType: ["", "他", "她"],
    hasMore: !0,
    qingyuan: {},
    logged: 0,
    showFilter: !1,
    animateCss: void 0,
    // 分类信息
    cate: {},
    // 搜索关键词
    searchKey: {},
    searchData: {
      age: "不限",
      height: "不限"
    },
    userCheck: {
      basic_check: 1,
      is_introduce: 1,
      more_check: 1,
      want_check: 1
    },
    tabtype: 0,
    serach: 0,
    kefu: 0,
    wenan: 0,
    s1: 0,
    curpage: 'index',
    backTopValue: false,
    nodata: false,
    list: [],
    allPages: 0,
    page: 1,
    loadMoreData: "下拉加载更多",
    backTopValue: false,
    top: 0,
  },
  backTop: function () {
    wx.pageScrollTo({
      scrollTop: 0
    })
  },
  onLoad: function () {
    this.getCate();
    //this.getData();
    http.get('config').then(data => {
      if (data.pian == "1") {
        wx.setNavigationBarTitle({
          title: '联系我们',
        })
        wx.redirectTo({
          url: '../user/company/index',
        });
        return false;
      }
      this.setData({
        config: data
      });
    });
    http.get('user', {
      uid: wx.getStorageSync("user").id
    }).then(data => {
      // 初始化用户数据
      this.initData();
      wx.setStorageSync('user', data)
      this.setData({
        user: data
      });
    });

  },
  onReady: function () {},
  didNotification: function () {
    this.userAuthorization()
  },
  userAuthorization: function () {

  },
  onShow: function () {
    http.get('config').then(data => {
      if (data.pian == "1") {
        wx.setNavigationBarTitle({
          title: '联系我们',
        })
        wx.redirectTo({
          url: '../user/company/index',
        });
        return false;
      }
    });
  },
  initData: function () {
    var searchKey = this.data.searchKey;
    // 赋值搜索年龄和身高
    var searchDataHandler = {
      age: requireUtil.ageConvert(searchKey.minAge || "", searchKey.maxAge || ""),
      height: requireUtil.heightConvert(searchKey.minHeight || "", searchKey.maxHeight || "")
    }
    // 传给serchdata
    this.setData({
      searchData: searchDataHandler
    })
    // 
    var d = {
      orderby: this.data.tabtype || 0,
      maxAge: searchKey.maxAge || 0,
      minAge: searchKey.minAge || 0,
      minHeight: searchKey.minHeight || 0,
      maxHeight: searchKey.maxHeight || 0,
      marriageString: searchKey.objectMarriageString || "",
      salaryString: searchKey.objectSalaryString || "",
      educationString: searchKey.objectEducationString || "",
      gender: wx.getStorageSync("user").gender == "1" ? 2 : 1,
      // gender: wx.getStorageSync("user").gender == "1" ? 1 : 2,
    };
    d.page = this.data.page;
    http.get('getindexlist', d).then(data => {
      if (data.list.length == 0) {
        this.setData({
          nodata: true
        });
      }
      if (this.data.page == 1) {
        var tempArray = [];
      } else {
        var tempArray = this.data.list;
      }
      var list = this.data.page == 1 ? data.list : tempArray.concat(data.list);
      list = list.length > 0 ? list : null;
      this.setData({
        list: list,
        allPages: data.totalPage
      });
      if (data.list == null) {
        this.setData({
          hasMore: 0
        });
      }
      console.log(list)
    });

  },
  getList: function (t) {

  },
  getData: function () {
    var t = this;

  },
  getLogin: function () {

  },
  getBottomLogin: function () {
    return configGetApp.WxService.showModal({
      title: "提示",
      showCancel: !0,
      cancelText: "再看看",
      confirmText: "去注册",
      content: "注册成为会员查看更多交友信息"
    }).then(function (t) {
      return 1 == t.confirm && configGetApp.WxService.navigateTo("/pages/register/step/step1")
    })
  },
  // 实名认证功能
  getCertUrl: function (t) {
    var e = t.currentTarget.dataset.id;
    var a = getApp();
    var user = a.WxService.getStorageSync("user")

    // if (user) {
      if (2 != this.data.user.isauth) return configGetApp.WxService.showModal({
        title: "提示",
        showCancel: !0,
        cancelText: "取消",
        confirmText: "去认证",
        content: "为保证平台用户真实性以及遵守相关运营规范，请完善您的实名认证信息"
      }).then(function (t) {
        return 1 == t.confirm && configGetApp.WxService.navigateTo("/pages/u/verify/step1")
      });
      configGetApp.WxService.navigateTo("/pages/index/member?id=", {
        id: e
      })
    // } else {
    //   (a.WxService.showLoading({
    //     title: "您还未登录"
    //   }), setTimeout(function () {
    //     a.WxService.hideLoading(), a.WxService.navigateTo("/pages/start/index")
    //   }, 1e3))
    // }

  },
  onPageScroll: function (e) {
    var that = this;
    var scrollTop = e.scrollTop
    var backTopValue = scrollTop > 150 ? true : false
    that.setData({
      backTopValue: backTopValue
    })
  },
  onPullDownRefresh() {
    var self = this;
    setTimeout(function () {
      if (self.data.page < self.data.allPages) {
        self.setData({
          page: self.data.page + 1
        });
        self.initData();
      } else {
        self.setData({
          loadMoreData: "没有数据了"
        });
      }
    }, 300);
  },
  onReachBottom() {
    var self = this;
    setTimeout(function () {
      if (self.data.page < self.data.allPages) {
        self.setData({
          page: self.data.page + 1
        });
        self.initData();
      } else {
        self.setData({
          loadMoreData: "没有数据了"
        });
      }
    }, 300);
  },
  setFilterPanel: function (t) {
    var a = this,
      e = this.data.cate;
    console.log(this.data.searchKey), e.salaryData.forEach(function (t, i) {
      t.value === a.data.searchKey.objectSalary && (e.salaryActionIndex = i)
    }), e.eduData.forEach(function (t, i) {
      t.value === a.data.searchKey.objectEducation && (e.eduActionIndex = i)
    }), this.setData({
      cate: e,
      showFilter: !this.data.showFilter,
      animateCss: "weui-animate-fade-in"
    })
  },
  maskHideFilter: function () {
    this.setData({
      showFilter: !1,
      animateCss: "weui-animate-fade-out"
    })
  },
  onEdu: function (t) {
    this.setData({
      "cate.eduActionIndex": t.detail.value,
      "searchKey.objectEducationString": this.data.cate.eduData[t.detail.value].name,
      "searchKey.objectEducation": this.data.cate.eduData[t.detail.value].value
    })
  },
  onSalary: function (t) {
    this.setData({
      "cate.salaryActionIndex": t.detail.value,
      "searchKey.objectSalaryString": this.data.cate.salaryData[t.detail.value].name,
      "searchKey.objectSalary": this.data.cate.salaryData[t.detail.value].value
    })
  },
  onMarriage: function (t) {
    this.setData({
      "cate.marriageActionIndex": t.detail.value,
      "searchKey.objectMarriageString": this.data.cate.marriageData[t.detail.value].name,
      "searchKey.objectMarriage": this.data.cate.marriageData[t.detail.value].value
    })
  },
  inputTapMinAge: function (t) {
    this.setData({
      "searchKey.minAge": t.detail.value
    })
  },
  inputTapMaxAge: function (t) {
    this.setData({
      "searchKey.maxAge": t.detail.value
    })
  },
  inputTapMinHeight: function (t) {
    this.setData({
      "searchKey.minHeight": t.detail.value
    })
  },
  inputTapMaxHeight: function (t) {
    this.setData({
      "searchKey.maxHeight": t.detail.value
    })
  },
  // 获取用户信息
  getCate: function () {
    var cate = this.data.cate,
      searchKey = this.data.searchKey,
      // 分类信息字符串化再decode解密,然后转json字符串得到数据
      res = JSON.parse(decodeURIComponent(JSON.stringify(requireCate.default)));
    res.eduData[0].name = "不限",
      res.salaryData[0].name = "不限",
      res.marriageData[0].name = "不限",
      // 重新赋值cate分类信息
      cate = {
        // 学历信息
        eduData: res.eduData,
        eduArr: res.eduData.map(function (value) {
          return value.name
        }),
        // 学历信息index排序根据搜索关键词的index排序或者默认排序即0
        eduActionIndex: searchKey.eduActionIndex || 0,
        // 收入信息
        salaryData: res.salaryData,
        salaryArr: res.salaryData.map(function (t) {
          return t.name
        }),
        salaryActionIndex: searchKey.salaryActionIndex || 0,
        // 婚姻信息
        marriageData: res.marriageData,
        marriageArr: res.marriageData.map(function (t) {
          return t.name
        }),
        marriageActionIndex: searchKey.marriageActionIndex || 0
      },
      // 把获取到的数据赋值给页面data
      this.setData({
        searchKey: searchKey,
        cate: cate
      })
  },
  resetSearchValue: function () {
    this.setData({
      searchKey: {},
      showFilter: !1,
      animateCss: "weui-animate-fade-out"
    }), this.initData();
  },
  confirmSearchValue: function () {
    var t = this.data.searchKey;
    this.maskHideFilter(), this.initData(), this.getList(t)
  },
  onUnload: function () {
    WxNotificationCenter.removeNotification("DecryptNotification", this)
  },
  onShareAppMessage: function () {
    return {
      title: this.data.config.sharetitle,
      path: "/pages/index/index",
      imageUrl: this.data.config.url + this.data.config.sharelogo
    }
  },
  maskHideModal: function () {
    this.setData({
      showModalStatus: !this.data.showModalStatus
    })
  },
  getLogUrl: function (t) {
    configGetApp.HttpService.wechatSetFormid({
      siteid: wx.getStorageSync("siteid"),
      formId: t.detail.formId
    }), wx.reLaunch({
      url: t.target.dataset.url
    })
  },
  getTabList: function (t) {
    var a = t.target.dataset.type;
    this.setData({
      tabtype: a
    }), this.initData(), this.getList({
      type: a
    })
  },
  showKefuEvent: function () {
    this.setData({
      showKefuStatus: !0
    })
  },
  hideKefuEvent: function () {
    this.setData({
      showKefuStatus: !1
    })
  },
  shower: function () {
    var current = this.data.config.url + this.data.config.gzh;
    wx.previewImage({
      current: current,
      urls: [current]
    })
  },
  checklogin: function (t) {
    var a = getApp()
    a.WxService.getStorageSync("user") ? this.getLogUrl(t) : (a.WxService.showLoading({
      title: "您还未登录"
    }), setTimeout(function () {
      a.WxService.hideLoading(), a.WxService.navigateTo("/pages/start/index")
    }, 1e3))
  }
});